package com.zklh.leetcode.other.problem1;

/**
 * @ClassName Palindrome
 * @Description 回文数算法实现
 * @Level C
 * @Author 坐看落花
 * @Date 2019/7/8 21:54
 * @Version 1.0
 **/
public class Palindrome {

    public boolean isPalindrome(int x) {
        if( x < 0 ){
            return false;
        }

        int tmpX = x;
        int length = 0;
        while(tmpX >= 1){
            tmpX /= 10;
            length++;
        }
        int[] arrX = new int[length];
        tmpX = x;
        int index = 0;
        while(tmpX >= 1){
            arrX[index++] = tmpX % 10;
            tmpX /= 10;
        }

        for(int i = 0; i <= length/2-1; i++){
            if(arrX[i] != arrX[length-1-i]){
                return false;
            }
        }
        return true;
    }


    public static void main(String[] args){
        Palindrome palindrome = new Palindrome();
        System.out.println(palindrome.isPalindrome(123123));
    }

}
